package stark.app.frame.player;

/**
 *  https://github.com/Jzvd/JZVideo
 *
 * */
import androidx.appcompat.app.AppCompatActivity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;

import com.bumptech.glide.Glide;

import cn.jzvd.JZUtils;
import cn.jzvd.Jzvd;
import cn.jzvd.JzvdStd;
import stark.app.R;
import stark.common.basic.constant.Extra;
import stark.common.basic.utils.IntentUtil;

public class VideoPlayerActivity extends AppCompatActivity {

    final String VIDEO_URL="http://jzvd.nathen.cn/c6e3dc12a1154626b3476d9bf3bd7266/6b56c5f0dc31428083757a45764763b0-5287d2089db37e62345123a1be272f8b.mp4";

    public static void play(Context context, String path) {
        Intent intent = IntentUtil.getIntent(context, VideoPlayerActivity.class);
        intent.putExtra(Extra.PATH, path);
        context.startActivity(intent);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video_player);

        String path = getIntent().getStringExtra(Extra.PATH);
        if (TextUtils.isEmpty(path)) {
            path = VIDEO_URL;
        }

        JzvdStd jzvdStd = findViewById(R.id.jz_video);
        jzvdStd.setUp(path
                , "饺子闭眼睛");
        Glide.with(this).load(path).into(jzvdStd.posterImageView);
    }

    @Override
    protected void onResume() {
        super.onResume();
        Jzvd.goOnPlayOnResume();

    }

    @Override
    protected void onPause() {
        super.onPause();
        //home back
        Jzvd.goOnPlayOnPause();
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Jzvd.releaseAllVideos();
    }

    @Override
    public void onBackPressed() {
        if (Jzvd.backPress()) {
            return;
        }
        super.onBackPressed();
    }

}